Function COUNT_TIME(range_data As Range, Optional ByVal sign As String = "、")

Dim nameArr, strDic
Dim nameStr As String
'创建对象集合
Set strDic = CreateObject("Scripting.Dictionary")

'循环读取区域单元格的值
For Each r_str In range_data
    '判断当前单元格是否为空
    If r_str.Value <> "" Then
    nameStr = nameStr + r_str.Value + sign
    End If
Next

'去除空格
nameStr = Replace(nameStr, " ", "")
'删除最后一位字符
nameStr = Left(nameStr, Len(nameStr) - 1)
'通过分隔符创建字符串数组
nameArr = Split(nameStr, sign)

'循环字符串数组
For Each strItem In nameArr
    Dim sartIndex As Integer
    Dim time As Double
    Dim lastName As String
    '查找英文括号位置
    sartIndex = InStr(strItem, "(")
    '如果没有找到，则查找中文括号
    If sartIndex = 0 Then
       sartIndex = InStr(strItem, "（")
    End If
    '如果当前姓名包含括号
    If sartIndex > 0 Then
        '截取括号前的名字
        lastName = Left(strItem, sartIndex - 1)
        
        Dim timeStr As String
        '截取括号内的数字字符串
        timeStr = Right(strItem, Len(strItem) - sartIndex)
        '去除最后的括号转换成Dobule类型的数字
        time = Val(Left(timeStr, Len(timeStr) - 1))
    Else
        '如果没有找到括号，则直接给lastName变量赋值
        lastName = strItem
        time = 0
    End If
    
    '判断当前名字是否存在于对象集合中
    If strDic.Exists(lastName) Then
        '如果存在则将数字相加
        strDic(lastName) = strDic.Item(lastName) + time
    Else
        '否则创建新的键值对
        strDic.Item(lastName) = time
    End If
    
    
Next

'nameStr赋空
nameStr = ""

'循环对象集合
For Each Key In strDic
    '拼接结果集字符串
    nameStr = nameStr + Key + "(" + CStr(strDic(Key)) + ")" + sign
Next

'去除最后一位字符
nameStr = Left(nameStr, Len(nameStr) - 1)
'去重空格
nameStr = Replace(nameStr, " ", "")
'返回最终结果
COUNT_TIME = nameStr

End Function
